"""
  Copyright 2008 Texas A&M University Licensed under the
  Educational Community License, Version 2.0 (the "License"); you may
  not use this file except in compliance with the License. You may
  obtain a copy of the License at
  
  http://www.osedu.org/licenses/ECL-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an "AS IS"
  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  or implied. See the License for the specific language governing
  permissions and limitations under the License.
"""

from sys import argv

from sqlalchemy.schema import MetaData

from meercat.storage.sqlalchemy.storage import SqlAlchemyStorage

def createTables(*args,**kwargs):
    """All arguments are passed directly into the constructor of the
    StorageEngine"""
    
    storage = SqlAlchemyStorage('temporary', *args,**kwargs)
    
    metadata = storage.Base.metadata
    
    metadata.create_all()
    
    session = storage.Session()
    session.commit()
    
    session.query(storage.Metadata).delete()
    session.query(storage.Instance).delete()
    session.query(storage.Resource).delete()
    session.commit()

def createTableScript():
    
    if len(argv) == 2:
        createTables(argv[1])
    else:
        print u'Usage: %s dbtype://connection_info\n See sqlalchemy documentation for the precise format' % (argv[0],)